package com.itcast.mapper;

import com.itcast.pojo.Emp;
import com.itcast.pojo.EmpQueryParam;
import com.itcast.pojo.JobOption;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/*
* 员工持久层接口
* */
@Mapper
public interface EmpMapper {

    //原始分页查询
//    /*
//    * 查询总记录数
//    * */
//    @Select("select count(*) from emp")
//    public long count();
//
//    /*
//    * 分页查询员工信息
//    * */
//    @Select("select  e.*,d.name as deptName from emp e left join dept d " +
//            "on e.dept_id = d.id order by e.update_time desc limit #{start},#{pageSize}")
//    public List<Emp> findByPage(Integer start,Integer pageSize);
    /*
    * PageHelper分页查询
    * 注意:
    *       1.PageHelper的Sql语句不能;结尾  -- 因为是拼接操作
    *       2.PageHelper只能执行第一条语句
    *
    * */
//    @Select("select  e.*,d.name as deptName from emp e left join dept d " +
//            "on e.dept_id = d.id order by e.update_time desc")
//    public List<Emp> findByPage();


//    @Select("select  e.*,d.name from emp e left join dept d on e.dept_id = d.id" +
//            "            where e.name LIKE CONCAT('%', #{name}, '%')" +
//            "        and e.gender =#{gender}" +
//            "        and e.entry_date between #{begin} and #{end}" +
//            "        order by e.update_time desc")
//    public List<Emp> findByPage(String name, Integer gender, LocalDate begin, LocalDate end);

//    public List<Emp> findByPage(String name, Integer gender, LocalDate begin, LocalDate end);

    public List<Emp> findByPage(EmpQueryParam empQueryParam);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into emp ( username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time)" +
            "values (#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void saveEmp(Emp emp);
    /*
    *
    * 批量删除员工
    * */
    void deleteEmpByID(List<Integer> ids);


    Emp findEmpById(Integer id);

    //根据id更新员工
//    @Update("update emp set username=#{username},password=#{password},name=#{name},gender=#{gender}," +
//            "phone=#{phone},job=#{job},salary=#{salary},image=#{image},entry_date=#{entryDate},dept_id=#{deptId},update_time=#{updateTime} where id=#{id}")
//    void updateEmp(Emp emp);
    //根据id更新员工
    void updateEmp(Emp emp);
//根据工作统计分组人数
//    JobOption countByJobOption();
    //根据工作统计分组人数
    @MapKey("pos")
    List<Map<String, Object>> countByEmpJobOption();

    @MapKey("name")
    List<Map<String, Integer>> countByEmpGenderOption();

    @Select("select * from emp")
    List<Emp> findAllEmp();

    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp selectByUsernameAndPassword(Emp emp);
}
